home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / Asm / Demos / Stars8.s < prev    next >
Encoding:
Text File  |  1998-05-07  |  7.6 KB  |  321 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Same as the first starfield demo but runs in 8 colours.  Default is 500
  3. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  4. ;real visual experience :-)
  5.  
  6.     INCDIR    "INCLUDES:"
  7.     INCLUDE    "dpkernel/dpkernel.i"
  8.  
  9. NSTARS    =    700    ;Number of stars
  10.  
  11. XSPEED    =    -4
  12. YSPEED    =    6
  13. ZSPEED    =    2
  14.  
  15. SCR_HEIGHT =    256
  16. SCR_WIDTH  =    320
  17.  
  18.     SECTION    "Demo",CODE
  19.  
  20. ;==========================================================================;
  21. ;                             INITIALISE DEMO
  22. ;==========================================================================;
  23.  
  24.     STARTDPK
  25.  
  26. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  27.     move.l    DPKBase(pc),a6
  28.     lea    ScreenTags(pc),a0
  29.     sub.l    a1,a1
  30.     CALL    Init
  31.     tst.l    d0
  32.     beq.s    .Exit
  33.  
  34.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  35.     CALL    Get
  36.     move.l    d0,JoyData
  37.     beq.s    .Exit
  38.     move.l    d0,a0    ;Initialise the joydata structure.
  39.     sub.l    a1,a1
  40.     CALL    Init
  41.     tst.l    d0
  42.     beq.s    .Exit
  43.  
  44.     move.l    Screen(pc),a0
  45.     CALL    Display
  46.  
  47.     bsr.s    Main
  48.  
  49. .Exit    move.l    DPKBase(pc),a6
  50.     move.l    JoyData(pc),a0
  51.     CALL    Free
  52.     move.l    Screen(pc),a0
  53.     CALL    Free
  54.     MOVEM.L    (SP)+,A0-A6/D1-D7
  55.     moveq    #ERR_OK,d0
  56.     rts
  57.  
  58. ;==========================================================================;
  59. ;
  60. ;==========================================================================;
  61.  
  62.     ;Randomize star coordinates
  63.  
  64. Main:    lea    StarCoords,a0    ;a0 = Ptr to star co-ordinates.
  65.     move.w    #NSTARS-1,d7
  66.     move.l    DPKBase(pc),a6
  67. .loop1    move.w    #8192,d1
  68.     CALL    SlowRandom
  69.     move.w    d0,(a0)+
  70.     CALL    SlowRandom
  71.     move.w    d0,(a0)+
  72.     CALL    SlowRandom
  73.     move.w    d0,(a0)+
  74.     dbra    d7,.loop1
  75.  
  76.     ;Construct perspective table
  77.  
  78.     lea    PersTable,a0    ;a0 = ptr to perspective table.
  79.     moveq    #0,d1    ;d1 = Starting at 0.
  80. .loop2    move.l    #$95FFFF,d2    ;d2 = $95FFFF
  81.     move.l    d1,d3    ;d3 = d1
  82.     add.w    #300,d3    ;d3 = ++300
  83.     divu    d3,d2    ;d2 = ($95ffff)/d3
  84.     move.w    d2,(a0)+    ;a0 = d2+
  85.     addq.w    #1,d1    ;d1 = ++1
  86.     cmp.w    #8192,d1    ;d1 = Equal to 8192?
  87.     bne.s    .loop2
  88.  
  89.     ;Construct plot tables for fast drawing.
  90.  
  91.     lea    PlotXTable,a0    ;a0 = X table - byte positions.
  92.     lea    PlotBTable,a1    ;a1 = Bit table (X related).
  93.     lea    PlotYTable,a2    ;a2 = Y table - line position.
  94.     moveq    #0,d0    ;d0 = 00
  95. .loop3    move.w    d0,d1    ;d1 = d0
  96.     lsr.w    #3,d1    ;d1 = (d0)<<3
  97.     move.w    d1,(a0)+    ;a0 = d1+
  98.  
  99.     move.w    d0,d1    ;d1 = d0
  100.     eor.w    #$FFFF,d1    ;d1 = (d0) eor $ffff
  101.     and.w    #%00000111,d1    ;d1 = &%00000111
  102.     move.w    d1,(a1)+    ;a1 = BitSet++
  103.  
  104.     cmp.w    #SCR_HEIGHT,d0    ;Write out the Y values for the
  105.     bge.s    .plot2    ;table.
  106.     move.w    d0,d1    ;d1 = Line Number.
  107.     mulu    #120,d1    ;d1 = (LineNumber)*80
  108.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  109.  
  110. .plot2    addq.w    #1,d0
  111.     cmp.w    #SCR_WIDTH,d0
  112.     bne.s    .loop3
  113.  
  114. ;==========================================================================;
  115. ;                                MAIN LOOP
  116. ;==========================================================================;
  117.  
  118. MainLoop:
  119.     move.l    SCRBase(pc),a6
  120.     CALL    scrWaitAVBL
  121.  
  122.     move.l    Screen(pc),a0
  123.     CALL    scrSwapBuffers
  124.  
  125. ;==========================================================================;
  126. ;                             STAR ANIMATION
  127. ;==========================================================================;
  128.  
  129.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  130.     add.w    #XSPEED,d0    ;d0 = (StarXPos)+XSPEED
  131.     add.w    #YSPEED,d1    ;d1 = (StarYPos)+YSPEED
  132.     add.w    #ZSPEED,d2    ;d2 = (StarZPos)+ZSPEED
  133.     and.w    #%0000011111111111,d0
  134.     and.w    #%0000011111111111,d1
  135.     and.w    #%0000011111111111,d2
  136.     movem.w    d0/d1/d2,StarXPos
  137.  
  138.     lea    Sinus(pc),a0    ;a0 = Sinus table.
  139.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  140.     add.w    (a0,d0.w),d3
  141.     add.w    (a0,d1.w),d4
  142.     add.w    (a0,d2.w),d5
  143.     movem.w    d3/d4/d5,StarXAdd
  144.  
  145. ;===========================================================================;
  146. ;                              SCREEN CLEAR
  147. ;===========================================================================;
  148. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  149.  
  150.     move.l    DPKBase(pc),a6
  151.     move.l    Screen(pc),a1    ;a1 = GameScreen
  152.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  153.     CALL    Clear
  154.  
  155. ;==========================================================================;
  156. ;                               DRAW STARS
  157. ;==========================================================================;
  158.  
  159.     move.l    DPKBase(pc),a6
  160.     move.l    Screen(pc),a0
  161.     CALL     Lock    ;>> = Must lock the screen.
  162.  
  163.     lea    StarCoords,a0    ;Draw starfield
  164.     lea    PersTable,a1    ;a1 = Perspective table.
  165.     lea    PlotXTable,a2    ;a2 = X table.
  166.     lea    PlotBTable,a3    ;a3 = Bit table.
  167.     lea    PlotYTable,a4    ;a4 = Y table.
  168.  
  169.     move.l    Screen(pc),a6
  170.     move.l    GS_MemPtr2(a6),a6
  171.  
  172.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  173.     add.w    #4096,d3    ;d3 = ++4096
  174.     add.w    #4096,d4    ;d4 = ++4096
  175.  
  176.     move.w    #NSTARS-1,d7
  177.  
  178. .draw    movem.w    (a0)+,d0/d1/d2    ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  179.     add.w    d3,d0    ;Increase XPos.
  180.     and.w    #8191,d0    ;d0 = And'd
  181.     sub.w    #4096,d0    ;d0 = --4096
  182.  
  183.     add.w    d4,d1    ;Y-movement
  184.     and.w    #8191,d1    ;d1 = And'd
  185.     sub.w    #4096,d1    ;d1 = --4096
  186.  
  187.     add.w    d5,d2    ;Z-movement
  188.     and.w    #8191,d2
  189.     add.w    d2,d2    ;d2 = *2 [word]
  190.     move.w    (a1,d2.w),d6    ;d6 = Read from Perspective table.
  191.  
  192.     muls    d6,d0    ;X-projection
  193.     swap    d0
  194.     add.w    #176,d0
  195.  
  196.     cmp.w    #SCR_WIDTH-1,d0
  197.     bhi    .nodraw
  198.     muls    d6,d1    ;Y-projection
  199.     swap    d1
  200.     add.w    #136,d1
  201.     cmp.w    #SCR_HEIGHT-1,d1
  202.     bhi    .nodraw
  203.  
  204.     add.w    d0,d0    ;d0 = *2 [word]
  205.     add.w    d1,d1    ;d1 = *2 [word]
  206.     move.w    (a4,d1.w),d6    ;d6 = Plot Y.
  207.     add.w    (a2,d0.w),d6    ;d6 = ++PlotX.
  208.     move.w    (a3,d0.w),d0    ;d0 = BitValue.
  209.  
  210. .draw1    cmp.w    #4000,d2    ;Now draw the star according to
  211.     bgt.s    .draw2    ;its position in the Z axis.
  212.     bset    d0,(a6,d6.w)
  213.     dbra    d7,.draw
  214.     bra.s    .done
  215.  
  216. .draw2    cmp.w    #6000,d2
  217.     bgt.s    .draw3
  218.     bset    d0,40(a6,d6.w)
  219.     dbra    d7,.draw
  220.     bra.s    .done
  221.  
  222. .draw3    cmp.w    #8000,d2
  223.     bgt.s    .draw4
  224.     bset    d0,(a6,d6.w)
  225.     bset    d0,40(a6,d6.w)
  226.     dbra    d7,.draw
  227.     bra.s    .done
  228.  
  229. .draw4    cmp.w    #10000,d2
  230.     bgt.s    .draw5
  231.     bset    d0,80(a6,d6.w)
  232.     dbra    d7,.draw
  233.     bra.s    .done
  234.  
  235. .draw5    cmp.w    #12000,d2
  236.     bgt.s    .draw6
  237.     bset    d0,(a6,d6.w)
  238.     bset    d0,80(a6,d6.w)
  239.     dbra    d7,.draw
  240.     bra.s    .done
  241.  
  242. .draw6    cmp.w    #14000,d2
  243.     bgt.s    .draw7
  244.     bset    d0,40(a6,d6.w)
  245.     bset    d0,80(a6,d6.w)
  246.     dbra    d7,.draw
  247.     bra.s    .done
  248.  
  249. .draw7    bset    d0,(a6,d6.w)
  250.     bset    d0,40(a6,d6.w)
  251.     bset    d0,80(a6,d6.w)
  252. .nodraw    dbra    d7,.draw
  253.  
  254. .done    move.l    DPKBase(pc),a6
  255.     move.l    Screen(pc),a0
  256.     CALL     Unlock
  257.  
  258.     move.l    JoyData(pc),a0
  259.     CALL    Query
  260.     move.l    JoyData(pc),a0
  261.     move.l    JD_Buttons(a0),d0
  262.     sub.l    a1,a1
  263.     moveq    #$00,d1
  264.     btst    #JB_LMB,d0
  265.     beq    MainLoop
  266.     rts
  267.  
  268. ;===========================================================================;
  269. ;                                  DATA
  270. ;===========================================================================;
  271.  
  272. JoyData:    dc.l  0
  273.  
  274. ScreenTags:    dc.l  TAGS_SCREEN
  275. Screen:        dc.l  0
  276.         dc.l  GSA_Width,320
  277.         dc.l  GSA_Height,256
  278.         dc.l  GSA_Attrib,SCR_TPLBUFFER
  279.         dc.l  GSA_ScrMode,SM_LORES
  280.         dc.l    GSA_BitmapTags,0
  281.         dc.l    BMA_Type,ILBM
  282.         dc.l    BMA_Palette,.palette
  283.         dc.l    TAGEND,0
  284.         dc.l  TAGEND
  285.  
  286. .palette    dc.l  PALETTE_ARRAY,8
  287.         dc.l  $000000,$f0f0f0,$c0c0c0,$909090 ;%000, %100, %010, %110
  288.         dc.l  $707070,$505050,$303030,$101010 ;%001, %101, %011, %111
  289.  
  290. ;===========================================================================;
  291. ;                                STAR DATA
  292. ;===========================================================================;
  293.  
  294. StarXAdd:    dc.w  33    ;Star stuff
  295. StarYAdd:    dc.w  12
  296. StarZAdd:    dc.w  -114
  297.  
  298. StarXPos:    dc.w  0    ;Sinus positions
  299. StarYPos:    dc.w  310
  300. StarZPos:    dc.w  1280
  301.  
  302.     INCLUDE    "GMSDev:source/asm/demos/StarSinus.i"
  303.  
  304.     SECTION    Storage,BSS
  305.  
  306. StarCoords:    ds.w  NSTARS*3    ;Star coordinates
  307. PersTable:    ds.w  8192    ;Perspective table
  308. PlotXTable:    ds.w  SCR_WIDTH    ;Plot tables
  309. PlotBTable:    ds.w  SCR_WIDTH
  310. PlotYTable:    ds.w  SCR_HEIGHT
  311.  
  312. ;===========================================================================;
  313.  
  314. ProgName:    dc.b  "3D Starfield 8",0
  315. ProgAuthor:    dc.b  "Paul Manias",0
  316. ProgDate:    dc.b  "January 1998",0
  317. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1998.  Freely distributable.",0
  318. ProgShort:    dc.b  "8 colour star field demonstration.",0
  319.         even
  320.  
  321.